package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketLog;
import com.cskaoyan.market.db.domain.MarketLogExample;
import com.cskaoyan.market.db.mapper.MarketLogMapper;
import com.cskaoyan.market.service.AdminLogService;
import com.cskaoyan.market.util.MybatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * Created with IntelliJ IDEA 2021.
 * User: Lazarus_Liu
 * Date: 2023/7/26
 * Time: 21:16
 * Description:
 */
public class AdminLogServiceImpl implements AdminLogService {

    @Override
    public List<MarketLog> getList(String page, String limit, String name, String sort, String order) {
        // 获取SqlSession
        SqlSession session = MybatisUtil.getSession();
        MarketLogMapper mapper = session.getMapper(MarketLogMapper.class);
        // 增加筛选条件
        MarketLogExample marketLogExample = new MarketLogExample();
        MarketLogExample.Criteria criteria = marketLogExample.createCriteria();
        if(!StringUtils.isEmpty(name)){
            criteria.andAdminEqualTo(name);
        }
        // 增加排序规则
        marketLogExample.setOrderByClause(sort + " " + order);
        // 分页
        PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));
        // 获取list
        List<MarketLog> marketLogs = mapper.selectByExample(marketLogExample);
        // 提交事务
        session.commit();
        session.close();
        // 返回list给controller
        return marketLogs;
    }
}
